# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: Mateusz Herych <heniekk@gmail.com>

# CAUTION: introduces soname change on *every* release:
# https://github.com/thestk/stk/issues/89
pkgbase=stk
pkgname=(stk stk-docs)
pkgver=4.6.2
pkgrel=2
pkgdesc='The Synthesis ToolKit in C++'
arch=(loong64 x86_64)
url="https://ccrma.stanford.edu/software/stk/"
license=(MIT)
makedepends=(alsa-lib doxygen gcc-libs glibc jack)
source=(https://github.com/thestk/$pkgname/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha512sums=('f1925744fdeddc9fccd24add52dbcc68b17c9f069be8d7d139b2a8a70d7d288881ec9effc564e1f43094a5395ddf45db7cc1339db17649abe0b8e0be2dc7bacd')
b2sums=('b15f052580b30f4aee314e6737dbff4193a25b552ea9f251832e3f39e4f623ddcf4550d6e2fcd227aad593dd2f4af518844e5f25082f676ce02e237810a4923a')

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --enable-shared
    --with-alsa
    --with-jack
  )
  cd $pkgname-$pkgver
  export RAWWAVE_PATH="/usr/share/$pkgname/rawwaves/"
  ./configure "${configure_options[@]}"
  make
  make -C projects/demo

  cd doc/doxygen
  doxygen
}

package_stk() {
  depends=(
    alsa-lib libasound.so
    gcc-libs
    glibc
    jack libjack.so
  )
  optdepends=(
    'stk-docs: for documentation'
    'tk: for demos and samples'
  )
  provides=("libstk-$pkgver.so")

  cd $pkgbase-$pkgver
  make DESTDIR="$pkgdir" install
  # license
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
  # demo
  install -vDm 755 projects/demo/stk-demo -t "$pkgdir/usr/bin"
  install -vDm 644 projects/demo/tcl/*.tcl -t "$pkgdir/usr/share/$pkgname/tcl"
  install -vDm 644 projects/demo/scores/{README,*.ski} -t "$pkgdir/usr/share/$pkgname/scores"
  install -vDm 644 rawwaves/*.{raw,c} -t "$pkgdir/usr/share/$pkgname/rawwaves"
}

package_stk-docs() {
  pkgdesc+=' - documentation'

  cd $pkgbase-$pkgver
  # docs
  install -vDm 644 doc/{README-Linux,ReleaseNotes,SKINI,hierarchy}.txt -t "$pkgdir/usr/share/doc/$pkgbase"
  install -vDm 644 doc/html/*.{html,png,js} -t "$pkgdir/usr/share/doc/$pkgbase/html"
  # license
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
